package com.manage.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.clms.common.R;
import com.manage.mapper.VipLevelMapper;
import com.manage.pojo.entity.TbMemberLevel;
import com.manage.pojo.vo.VipLevelVo;
import com.manage.service.VipLevelService;
import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * @program: clms-third
 * @description: 会员等级业务层
 * @author: 林子洁
 * @create: 2021-07-23 14:58
 **/
@Service
public class VipLevelServiceImpl implements VipLevelService {
    @Resource
    private VipLevelMapper levelMapper;

    @Override
    public R initVipLevel(Integer currentPage, Integer pageSize, VipLevelVo vipLevelVo) {
        //模糊查询 账户和昵称
        QueryWrapper<TbMemberLevel> wrapper=new QueryWrapper<>();
        if(StringUtils.isNotEmpty(vipLevelVo.getName())){
            wrapper.like("name", vipLevelVo.getName());
        }
        //分页
        Page<TbMemberLevel> levelPage=new Page<>(currentPage,pageSize);
        levelMapper.selectPage(levelPage,wrapper);
        return R.ok().put("records",levelPage.getRecords()).put("total",levelPage.getTotal());

    }

    @Override
    public R deleteVipLevel(Integer id) {
        levelMapper.deleteById(id);
        return R.ok().message("删除成功");
    }

    @Override
    public R updateLevel(TbMemberLevel memberLevel) {
        levelMapper.updateById(memberLevel);
        return R.ok().message("修改成功");
    }

    @Override
    public R insertLevel(TbMemberLevel memberLevel) {
        levelMapper.insert(memberLevel);
        return R.ok().message("添加成功");
    }

    @Override
    public R selectByVipId(Integer id) {
        TbMemberLevel tbMemberLevel = levelMapper.selectById(id);
        return R.ok().put("VipInfo",tbMemberLevel);
    }
}
